#!/bin/bash
file_name=functions.sh
funcs=`which $file_name`
if [ "$funcs" != "" ] ;then
  echo "funcs=$funcs"
  . $funcs
else
  funcs=`dirname $0`/$file_name
  echo "$PWD"
  echo "funcs=$funcs"
  if [ "$funcs" != "" ] ;then
    . $funcs
  else
    exit
  fi
fi

function install_nx()
{
  `dirname $0`/setup-ssh.sh
  sudo chmod 755 /usr/lib/cups/backend/ipp
  deb_list="
  http://64.34.161.181/download/3.5.0/Linux/nxclient_3.5.0-7_i386.deb
  http://64.34.161.181/download/3.5.0/Linux/nxnode_3.5.0-7_i386.deb
  http://64.34.161.181/download/3.5.0/Linux/FE/nxserver_3.5.0-9_i386.deb"
  for deb in $deb_list
  do
    sh_wget $deb  ~/downloads/ 
    deb_name=`basename $deb`
    if test -f ~/downloads/$deb_name; then
      pkg=`echo $deb_name |awk -F '_' '{print $1}'`
      echo "pkg=$pkg"
      if  ! sh_dpkg_status $pkg;then
        sudo dpkg -i  ~/downloads/$deb_name
      fi
    fi
  done
  if test -f  /usr/NX/bin/nxserver; then
    sudo /usr/NX/bin/nxserver --useradd $USER --system 
    sudo /usr/NX/bin/nxserver --restart
  fi
}

function add_user()
{
  local username=
  local password=
  result=`question "请输入用户名" 2 "$username"`
  username=$result
  sudo /usr/NX/bin/nxserver --useradd $username --system 
  if test -d /home/$username; then
    echoTextBlue "修改 /home/$username 属性"
    sudo chmod 750 /home/$username
  fi
  sudo /usr/NX/bin/nxserver --restart
}

function install()
{
  sudo apt-get install python-software-properties
  sudo add-apt-repository ppa:freenx-team
  sudo apt-get update
  sudo apt-get install neatx-server

}

menu_list="
add-user
install"
result=`sh_menu_select "$menu_list"`

if [ "$result" = "add-user" ]; then
   add_user
elif [ "$result" = "install" ]; then
   install_nx
fi




exit
	输入密码: mimimama
	NX> 102 Password: 
	NX> 102 Confirm password: 
	NX> 900 Setting password for user: nxuserone.
	NX> 137 System password changed correctly.
	NX> 304 User: nxuserone added to the system.
	NX> 801 User: nxuserone uses SSHD authentication.
	NX> 301 User: nxuserone enabled in the NX user DB.
	NX> 999 Bye.
5. 重启 NX 
	./nxserver --restart





